//
//  HomeBtnView.m
//  大轮胎
//
//  Created by 朱永超 on 2017/3/22.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "HomeBtnView.h"
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
@implementation HomeBtnView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        NSArray *titleArr = @[@"知识",@"动态",@"展会",@"更多"];
        CGFloat x = 0;
        for (int i = 0; i < 4 ; i++) {
            x = (SCREENWIDTH/4)*i;
            self.toolBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, 0, SCREENWIDTH/4,self.frame.size.height)];
            self.toolBtn.tag = i;
            [self.toolBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%dhomeBtn",i]] forState:0];
            [self.toolBtn setTitle:titleArr[i] forState:0];
            self.toolBtn.titleLabel.font = [UIFont systemFontOfSize:14];
            [self.toolBtn setTitleColor:[UIColor blackColor] forState:0];
            self.toolBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
            [self.toolBtn setTitleEdgeInsets:UIEdgeInsetsMake(self.toolBtn.imageView.frame.size.height+25 ,-self.toolBtn.imageView.frame.size.width, 10,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
            [self.toolBtn setImageEdgeInsets:UIEdgeInsetsMake(-20, 0.0,0.0, -self.toolBtn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
            [self.toolBtn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.toolBtn];
        }
    }
    return self;
}
-(void)btn:(UIButton *)click
{
    if (click.tag == 0)
    {
        NSLog(@"轮胎知识");
    }
    else if (click.tag == 1)
    {
        NSLog(@"行业动态");
    }
    else if (click.tag == 2)
    {
        NSLog(@"展会信息");
    }
    else if (click.tag == 3)
    {
        NSLog(@"更多");
    }
}

@end
